package org.example.demo.controller;

import org.example.demo.entity.Department;
import org.example.demo.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/der")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;


    @GetMapping
    public List<Department> getall(){
        return departmentService.getAll();
    }
    @GetMapping("/{id}")
    public Department get(@PathVariable Integer id){
        return departmentService.get(id);
    }
    @PostMapping
    public int add(@RequestBody Department department){
        return departmentService.add(department);
    }
    @DeleteMapping("/{id}")
    public int del(@PathVariable Integer id){
        return departmentService.del(id);
    }

    @PutMapping
    public int update(@RequestBody Department department){
        return departmentService.updatew(department);

    }
}
